package top.kaoshanji.p1ch09b;

import java.util.Random;

/**
 * 代码清单-p1ch09b-200页a：一个随机产生形状的工厂
 * author kaoshanji
 * ^_^
 * create time 2025/3/9 18:34
 */
public class RandomShapes {

    private Random rand = new Random(47);

    public Shape get() {
        switch (rand.nextInt(3)) {
            default:
            case 0: return new Circle();
            case 1: return new Square();
            case 2: return new Triangle();
        }
    }

    public Shape[] array(int sz) {
        Shape[] shapes = new Shape[sz];

        // 用各种形状填满数组
        for (int i = 0; i < shapes.length; i++) {
            shapes[i] = get();
        }

        return shapes;
    }


}
